package com.atguigu.servicebase.exceptionHandler;

import com.atguigu.commonutil.R;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(ArithmeticException.class)
    public R arithmeticExceptionHandler(ArithmeticException e) {
        e.printStackTrace();
        return R.error().message("执行了算术异常处理....");
    }

    @ExceptionHandler(Exception.class)
//    @ResponseBody
    public R exceptionHandler(Exception E) {
        E.printStackTrace();
        return R.error().message("执行了全局异常处理....");
    }

    @ExceptionHandler(MyException.class)
    public R myExceptionHandler(MyException e) {
        log.error(e.getMsg());
        e.printStackTrace();
        return R.error().code(e.getCode()).message(e.getMsg());
    }

}
